package com.feignfilter.backend1.exceptionHandler;

import com.feignfilter.backend1.exception.BaseException;
import com.feignfilter.common.BaseReturnBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@ControllerAdvice
public class CommonExceptionHandler {
    @ExceptionHandler(value = BaseException.class)
    public BaseReturnBean baseExceptionHandler(Exception e){
        BaseReturnBean bean = new BaseReturnBean();
        System.out.println("发生了一个异常，进行包装"+e);
        bean.setReturnCode("wrappered message");
        bean.setReturnMessage("这是包装BaseException后的消息");
        return bean;
    }

    @ExceptionHandler(value = Exception.class)
    public BaseReturnBean exceptionHandler(Exception e){
        BaseReturnBean bean = new BaseReturnBean();
        System.out.println("发生了一个异常，进行包装"+e);
        bean.setReturnCode("wrappered message");
        bean.setReturnMessage("这是包装Exception后的消息");
        return bean;
    }
}
